package views;

import java.awt.GridLayout;
import java.awt.event.ActionListener;
import java.awt.event.WindowListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

import components.JButtonPeca;
import components.JPanelInfo;


@SuppressWarnings("serial")
public class JogoGUI extends JFrame {

	private int matriz = 10;
	public JButton btSair;
	public JButtonPeca[][] btItem;
	public JPanelInfo jpInfo = new JPanelInfo();
		
	public JogoGUI(String server, int matriz){
		super();
		this.matriz = matriz;
		setTitle("JMemory - " + server);
		setResizable(false);
		setComponentes();
		setSize(800,600);
		setLocationRelativeTo(null);
	}

	public void setJogador(String jogNome) {
		this.setTitle(getTitle() + " - " + jogNome);
	}
	
	private void setComponentes() {
		btSair = new JButton("Sair");
		JPanel jpItems = new JPanel();
		jpItems.setLayout(new GridLayout(matriz, matriz,5,5));
		btItem = new JButtonPeca[matriz][matriz];
		for (int i = 0; i < matriz; i++) 
			for (int j = 0; j < matriz; j++){
				btItem[i][j] = new JButtonPeca();
				btItem[i][j].setSize(36, 36);
				btItem[i][j].setPx(i);
				btItem[i][j].setPy(j);
				jpItems.add(btItem[i][j]);
			}
		
		jpInfo.setBounds(2, 0, 790, 124);
		jpItems.setBounds(2, 125, 790, 445);
		this.setLayout(null);
		jpInfo.add(btSair);
		this.add(jpInfo);
		this.add(jpItems);
	}

	public void setListener(ActionListener actionListener, WindowListener wl){
		btSair.addActionListener(actionListener);
		for (JButtonPeca[] itemLinha : btItem) 
			for (JButtonPeca item : itemLinha) 
				item.addActionListener(actionListener);
		this.addWindowListener(wl);
	}

}
